/** This is a helper class for starting some external programs 
 *  @author Copyright (c) 2003-2005 by chrmac@gmx.de */

package com.jtalker.client;

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * Executes a process
 * @author  ChrM
 */

public class ProcessExecuter {
   /** Executes a process 
    *  @param _binary Path to the executable binary 
    *  @param _params Parameters for the binary
    *  @param _use_graphics If true, it uses graphics for outputs, else it runs in text mode only */
   public static boolean execute(String _binary, String _params, boolean _use_graphics) {
      try {
	 java.lang.Runtime.getRuntime().exec(_binary + " " +  _params);
      } catch (Exception _e) {
	 System.err.println("*** Can't execute process: " + _e.toString());
	 if(_use_graphics) {
	   javax.swing.JOptionPane.showMessageDialog(null, 
						"Can't execute:\n" + _binary + "\n" + _e.toString(), 
						"Error", 
						javax.swing.JOptionPane.ERROR_MESSAGE); 
	 }
	 return false;
      }

      return true;
   }
}
